package work823;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class work3Clent {
  public static void main(String[] args) {
    Socket socket = null;
    ObjectOutputStream oos = null;
    try {
      socket = new Socket("localhost",8888);
      OutputStream os = socket.getOutputStream();
      InputStream is = socket.getInputStream();
      oos = new ObjectOutputStream(os);
        Scanner sc = new Scanner(System.in);
        if (socket.isConnected()){
          System.out.println("请输入用户名：");
          String name  = sc.next();
          System.out.println("请输入密码：");
          String password = sc.next();
          work3User user = new work3User(name,password);
          oos.writeObject(user);
          socket.shutdownOutput();
        }
      byte[] buf = new byte[1024];//创建字节数组，临时存储数据区域 === 数据缓冲区,1KB= 1024bytes
      int len ;
      while ((len = is.read(buf))!= -1){
        String content = new String(buf,0,len);
        System.out.println(content);
      }
     socket.shutdownInput();
    } catch (Exception e) {
      e.printStackTrace();
    }finally {
      try {
        oos.close();
        socket.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}
